<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" template="/paginas/template.xhtml">



	<ui:define name="corpoForm">
		


		<h:form id="formBotoesDespesa" prependId="false">
			<p:panelGrid columns="1" styleClass="botoes" id="botoes">
				<p:commandButton id="botaoCriarDespesa" value="#{rsc.label_criar}"
					rendered="#{p:ifGranted('CRIAR_DESPESA')}" styleClass="botao"
					action="#{manterDespesaBean.criarEntidade}" ajax="false"
					title="#{rsc.title_criar}" />
			</p:panelGrid>
		</h:form>

		<f:event type="javax.faces.event.PreRenderComponentEvent"
			listener="#{manterDespesaBean.preRenderList}" />
		<h:form id="formListDespesa" prependId="false">

			<p:fieldset legend="#{rsc.label_filtros}" toggleable="true"
				collapsed="true">
				<p:panelGrid columns="5">
					<p:outputLabel value="#{rsc.label_despesa} " for="acDespesa" />

					<p:outputLabel value="#{rsc.label_conta}" for="cmbConta" />

					<p:outputLabel value="#{rsc.label_categoriaFinanceira}"
						for="cmbCategoriaFinanceira" />

					<p:outputLabel value="#{rsc.label_ativo}" for="cmbAtivo" />

					<p:spacer />

					<p:autoComplete id="acDespesa" minQueryLength="3" size="42"
						value="#{manterDespesaBean.filtro.nome}" effect="fade"
						maxResults="7"
						completeMethod="#{manterDespesaBean.autoCompleteNome}">
						<p:ajax event="change"
							listener="#{manterDespesaBean.buscarPorFiltros}"
							update="listaDespesa" />
					</p:autoComplete>

					<p:selectOneMenu label="#{rsc.label_conta}"
						value="#{manterDespesaBean.filtro.conta}" id="cmbConta">
						<p:ajax event="change"
							listener="#{manterDespesaBean.buscarPorFiltros}"
							update="listaDespesa" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterDespesaBean.formulario.contas}"
							var="c" itemLabel="#{c.nome}" itemValue="#{c.id}" />
					</p:selectOneMenu>

					<p:selectOneMenu label="#{rsc.label_categoriaFinanceira}" height="400"
						value="#{manterDespesaBean.filtro.categoriaFinanceira}"
						id="cmbCategoriaFinanceira">
						<p:ajax event="change"
							listener="#{manterDespesaBean.buscarPorFiltros}"
							update="listaDespesa" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterDespesaBean.formulario.categorias}"
							var="c" itemLabel="#{c.nome}" itemValue="#{c.id}" />
					</p:selectOneMenu>

					<p:selectOneMenu label="#{rsc.label_ativo}"
						value="#{manterDespesaBean.filtro.ativo}" id="cmbAtivo">
						<p:ajax event="change"
							listener="#{manterDespesaBean.buscarPorFiltros}"
							update="listaDespesa" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterDespesaBean.status}" var="c"
							itemLabel="#{c.label}" itemValue="#{c}" />
					</p:selectOneMenu>

					<p:commandButton update="listaDespesa"
						actionListener="#{manterDespesaBean.buscarPorFiltros}"
						icon="ui-icon ui-icon-search" title="#{rsc.label_buscar}" />
				</p:panelGrid>
			</p:fieldset>

			<p:panel id="pnlListaDespesa"
				header="#{rsc.label_despesasCadastradas}" toggleable="true"
				toggleSpeed="500">

				<p:panelGrid columns="1" styleClass="full-width"
					columnClasses="full-width">
					<p:dataTable emptyMessage="#{msg.nenhumRegistroEncontrado}"
						var="despesa" id="listaDespesa" sortMode="multiple"
						widgetVar="listaDespesaWid" value="#{manterDespesaBean.entidades}"
						paginator="true" rows="10"
						paginatorPosition="#{rsc.label_paginationPosition}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="10,50,150,200">

						<p:column headerText="#{rsc.label_despesa}"
							sortBy="#{despesa.nome}">
							<p:outputLabel value="#{despesa.nome}" />
						</p:column>
						
						<p:column headerText="#{rsc.label_conta}"
							sortBy="#{despesa.conta.nome}">
							<p:outputLabel value="#{despesa.conta.nome}" />
						</p:column>

						<p:column headerText="#{rsc.label_ativo}"
							sortBy="#{despesa.ativo}" styleClass="centralizado">
							<p:outputLabel value="#{rsc.label_sim}"
								rendered="#{despesa.ativo}" />
							<p:outputLabel value="#{rsc.label_nao}"
								rendered="#{!despesa.ativo}" />
						</p:column>


						<p:column styleClass="coluna-acoes"
							headerText="#{rsc.label_acoes}">

							<p:commandButton update=":habilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_DESPESA') and !despesa.ativo}"
								oncomplete="habilitar.show();" icon="ui-icon ui-icon-locked"
								title="#{rsc.label_habilitar}">
								<f:setPropertyActionListener value="#{despesa}"
									target="#{manterDespesaBean.entidade}" />
							</p:commandButton>

							<p:commandButton update=":desabilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_DESPESA') and despesa.ativo}"
								oncomplete="desabilitar.show();" icon="ui-icon ui-icon-unlocked"
								title="#{rsc.label_desabilitar}">
								<f:setPropertyActionListener value="#{despesa}"
									target="#{manterDespesaBean.entidade}" />
							</p:commandButton>

							<p:commandButton icon="ui-icon ui-icon-pencil"
								rendered="#{p:ifGranted('ALTERAR_DESPESA')}"
								title="#{rsc.label_editar}" ajax="false" action="editarDespesa">
								<f:setPropertyActionListener value="#{despesa}"
									target="#{manterDespesaBean.entidade}" />
							</p:commandButton>

						</p:column>
					</p:dataTable>
				</p:panelGrid>
			</p:panel>
			<p:watermark value="#{rsc.wm_nomeDespesaConsulta}" for="acDespesa" />	
		</h:form>

		<p:confirmDialog message="#{msg.questionConfirmaHabilitar}"
			appendTo="@(body)" width="250" id="habilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="habilitar">
			<h:form id="habilitarForm">
				<p:commandButton value="#{rsc.label_sim}" styleClass="botao"
					actionListener="#{manterDespesaBean.habilitar}"
					oncomplete="habilitar.hide()"
					update=":formListDespesa:listaDespesa, :growl" />
				<p:commandButton value="#{rsc.label_nao}" styleClass="botao"
					onclick="habilitar.hide()" type="button" />
			</h:form>
		</p:confirmDialog>

		<p:confirmDialog message="#{msg.questionConfirmaDesabilitar}"
			appendTo="@(body)" width="250" id="desabilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="desabilitar">
			<h:form id="desabilitarForm">
				<p:commandButton value="#{rsc.label_sim}" styleClass="botao"
					actionListener="#{manterDespesaBean.desabilitar}"
					oncomplete="desabilitar.hide()"
					update=":formListDespesa:listaDespesa, :growl" />
				<p:commandButton value="#{rsc.label_nao}" styleClass="botao"
					onclick="desabilitar.hide()" type="button" />
			</h:form>
		</p:confirmDialog>

	</ui:define>
</ui:composition>

